<template>
  <header>
    <div class="l-content">
      <el-button type="primary" icon="el-icon-menu" size="mini" @click="collapseMenu"></el-button>
      <el-breadcrumb separator="/">
        <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item v-if="current">
          <router-link :to="current.path">{{ current.label }}</router-link>
        </el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <div class="r-content">
      <el-dropdown size="mini">
        <span class="el-dropdown-link"><img :src="userImg" class="userImg"/></span>
        <el-dropdown-menu slot="dropdown">
          <el-dropdown-item>个人中心</el-dropdown-item>
          <el-dropdown-item @click.native="logOut">退出</el-dropdown-item>
        </el-dropdown-menu>
      </el-dropdown>
    </div>
  </header>
</template>

<script>
import { mapState } from 'vuex'
export default {
  data() {
    return {
      userImg: require('../assets/images/logo.png'),
    }
  },
  computed: {
    ...mapState({
      current: state => state.tab.currentMenu,
    }),
  },
  methods: {
    collapseMenu() {
      this.$store.commit('collapse')
    },
    logOut() {
      this.$store.commit('clearToken')
      this.$store.commit('clearMenu')
      location.reload()
    },
  },
}
</script>

<style lang="scss" scoped>
header {
  display: flex;
  height: 100%;
  align-items: center;
  justify-content: space-between;
}
.el-breadcrumb__inner a {
  color: #ffffff !important;
}
span {
  color: #ffffff !important;
}

.l-content {
  display: flex;
  align-items: center;
}
.l-content .el-button {
  margin-right: 30px;
}
.r-content .userImg {
  width: 54px;
  height: 54px;
  border-radius: 50%;
}
</style>
